import 'package:flutter/material.dart';
import 'package:navigator_demo/navigator2pointzero/tab/common_page.dart';

import 'package:navigator_demo/navigator2pointzero/tab/home.dart';

class AppRouterFactory {
  static Route<dynamic> routeFactory(RouteSettings routeSettings) {
    switch (routeSettings.name) {
      case '/':
        return MaterialPageRoute(
          builder: (context) => HomePage(),
        );
      default:
        return PageRouteBuilder(
          transitionDuration: Duration(seconds: 2),
          settings: routeSettings,
          pageBuilder: (context, animation, secondAnimation) {
            final entryTween = Tween(
              begin: Offset(-1.0, 0.0),
              end: Offset.zero,
            )
                .chain(
                  CurveTween(curve: Curves.easeOut),
                )
                .animate(animation);
            final exitTween = Tween(
              begin: Offset.zero,
              end: Offset(-1.0, 0.0),
            )
                .chain(
                  CurveTween(curve: Curves.easeIn),
                )
                .animate(secondAnimation);
            return SlideTransition(
              position: entryTween,
              child: SlideTransition(
                position: exitTween,
                child: CommonPage(
                  title: routeSettings.name,
                ),
              ),
            );
          },
        );
    }
  }
}
